$().ready(function(){
    let page = {
        p:1,
        num:5,
        type:2,//2为订货列表   1为售货列表
        status:10,
        start_time:'',
        end_time:''
    }
    function init(){
        //获取列表
        getOrderList(page.type,page.p,page.num,page.status,global.community_id,page.start_time,page.end_time);
    }
    init();
    //导航切换
   $('.nav').on('click','.nav-item',function(){
       $('.nav-item').removeClass('active');
       $(this).addClass('active');
       let status = $(this).data('status');
       page.status = status;
       getOrderList(page.type,page.p,page.num,page.status,global.community_id,page.start_time,page.end_time);
       // console.log(status);
   })
    //嵌套模板字符
    function mbzi(list){
       let html = '';
       for(let i in list){
           html += `
             <div class="product_info">
                <div class="img-box">
                   <img src="${list[i].head_img}" alt="">
                </div>
                <div class="product_title">${list[i].product_name}</div>
                <div class="book_num">X ${list[i].num}</div>
             </div>
           `

       }
       return html;
    }
    //再次支付
    function payAgain(status,id){
       let html = '';
       if(status == 0){
           html += `
             <span data-id="${id}">支付</span>
           `
       }
       return html;
    }
    //获取列表
    function getOrderList(type,p,num,status,community_id,start_time,end_time){
       let data = {};
       if(type == 1){
           data = {
               type:type,//2为订货列表   1为售货列表
               status:status,//10 全部
               start_time:start_time,
               end_time:end_time,
               community_shop_id:community_id,//type:1
               num:num,
               p:p
           }
       }
       if(type == 2){
           data = {
               type:type,//2为订货列表   1为售货列表
               status:status,//10 全部
               start_time:start_time,
               end_time:end_time,
               buy_community_id:community_id,
               num:num,
               p:p
           }
       }
       getAjax(`${global.apiUrl}/Api/Alssy/get_als_product_order`,res=>{
           console.log(res);
           let html = '';
           let list = res.list;
           if(list.length != 0){
               $('#page').paging({
                   pageNo:p,
                   totalSize:res.count,
                   totalPage:Math.ceil(res.count/num),
                   callback(pages){
                        page.p =pages;
                        getOrderList(page.type,page.p,page.num,page.status,global.community_id,page.start_time,page.end_time);
                   }
               });
               for(let i in list){
                   html += `
                    <div class="my-order-item">
                        <div class="t_head">
                            <div>${setTime2(list[i].createtime)}</div>
                            <div>订单号：<span style="color:#444;">${list[i].order_num}</span></div>
                        </div>
                        <div class="t_body">
                            <div class="width_60 product_list_box">
                                ${mbzi(list[i].content)}
                            </div>
                            <div class="width_10 pd_t10 tac br">${list[i].name}</div>
                            <div class="width_10 pd_t10 tac br">${list[i].all_price}</div>
                            <div class="width_10 pd_t10 tac br ${list[i].status==0?'red-color':'yellow-color'}">${list[i].status==0?'未支付':'支付完成'}</div>
                            <div class="width_10 pd_t10 tac" style="color:#0b67ff">
                                
                                   ${payAgain(list[i].status,list[i].id)}
                             
                            </div>
                        </div>
                    </div>

               `
               }

           }
           $('#list').html(html);
       },data)
    }
});
